<HTML><HEAD><TITLE>/home/steder/PythonLectures/BobChat-v0.3/BobClient.py</TITLE></HEAD>
                  <BODY BGCOLOR=#FFFFFF>
                  <!--header-->
                  <!--script--><PRE><FONT COLOR=#1111CC>#!/usr/bin/env python</FONT>
<FONT COLOR=#1111CC># pygame + PyOpenGL version of Nehe's OpenGL lesson06</FONT>
<FONT COLOR=#1111CC># Paul Furber 2001 - m@verick.co.za</FONT>

<FONT COLOR=#3333CC><B>import</B></FONT> os
<FONT COLOR=#3333CC><B>from</B></FONT> OpenGL.GL <FONT COLOR=#3333CC><B>import</B></FONT> *
<FONT COLOR=#3333CC><B>from</B></FONT> OpenGL.GLU <FONT COLOR=#3333CC><B>import</B></FONT> *
<FONT COLOR=#3333CC><B>import</B></FONT> pygame, pygame.image
<FONT COLOR=#3333CC><B>from</B></FONT> pygame.locals <FONT COLOR=#3333CC><B>import</B></FONT> *

xrot = yrot = zrot = 0.0
textures = [0,0]

<FONT COLOR=#3333CC><B>def</B></FONT><A NAME="resize"><FONT COLOR=#CC0000><B> resize</B></FONT></A>((width, height)):
    <FONT COLOR=#3333CC><B>if</B></FONT> height==0:
        height=1
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45, 1.0*width/height, 0.1, 100.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

<FONT COLOR=#3333CC><B>def</B></FONT><A NAME="init"><FONT COLOR=#CC0000><B> init</B></FONT></A>():
    glEnable(GL_TEXTURE_2D)
    load_textures()
    glShadeModel(GL_SMOOTH)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glClearDepth(1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

<FONT COLOR=#3333CC><B>def</B></FONT><A NAME="load_textures"><FONT COLOR=#CC0000><B> load_textures</B></FONT></A>():
    texturefile = os.path.join(<FONT COLOR=#115511>'data'</FONT>,<FONT COLOR=#115511>'nehe.bmp'</FONT>)
    textureSurface = pygame.image.load(texturefile)
    textureData = pygame.image.tostring(textureSurface, <FONT COLOR=#115511>"RGBX"</FONT>, 1)

    glBindTexture(GL_TEXTURE_2D, textures[0])
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, textureSurface.get_width(), textureSurface.get_height(), 0,
                  GL_RGBA, GL_UNSIGNED_BYTE, textureData );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)


<FONT COLOR=#3333CC><B>def</B></FONT><A NAME="draw"><FONT COLOR=#CC0000><B> draw</B></FONT></A>():
    <FONT COLOR=#3333CC><B>global</B></FONT> xrot, yrot, zrot

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glTranslatef(0.0,0.0,-5.0)

    glRotatef(xrot,1.0,0.0,0.0)
    glRotatef(yrot,0.0,1.0,0.0)
    glRotatef(zrot,0.0,0.0,1.0)
    
    
    glBegin(GL_QUADS)
	
    <FONT COLOR=#1111CC># Front Face (note that the texture's corners have to match the quad's corners)</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
	
    <FONT COLOR=#1111CC># Back Face</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
	
    <FONT COLOR=#1111CC># Top Face</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f( 1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
	
    <FONT COLOR=#1111CC># Bottom Face       </FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
	
    <FONT COLOR=#1111CC># Right face</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
	
    <FONT COLOR=#1111CC># Left Face</FONT>
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0)	<FONT COLOR=#1111CC># Bottom Left Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0)	<FONT COLOR=#1111CC># Bottom Right Of The Texture and Quad</FONT>
    glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0,  1.0)	<FONT COLOR=#1111CC># Top Right Of The Texture and Quad</FONT>
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0)	<FONT COLOR=#1111CC># Top Left Of The Texture and Quad</FONT>
	
    glEnd();				
    
    xrot = xrot + 0.2
    yrot = yrot + 0.2
    zrot = zrot + 0.2
        

<FONT COLOR=#3333CC><B>def</B></FONT><A NAME="main"><FONT COLOR=#CC0000><B> main</B></FONT></A>():

    video_flags = OPENGL|DOUBLEBUF
    
    pygame.init()
    surface = pygame.display.set_mode((640,480), video_flags)

    resize((640,480))
    init()

    frames = 0
    ticks = pygame.time.get_ticks()
    <FONT COLOR=#3333CC><B>while</B></FONT> 1:
        event = pygame.event.poll()
        <FONT COLOR=#3333CC><B>if</B></FONT> event.type == QUIT <FONT COLOR=#3333CC><B>or</B></FONT> (event.type == KEYDOWN <FONT COLOR=#3333CC><B>and</B></FONT> event.key == K_ESCAPE):
            <FONT COLOR=#3333CC><B>break</B></FONT>
        
        draw()
        pygame.display.flip()
        frames = frames+1

    <FONT COLOR=#3333CC><B>print</B></FONT> <FONT COLOR=#115511>"fps:  %d"</FONT> % ((frames*1000)/(pygame.time.get_ticks()-ticks))


<FONT COLOR=#3333CC><B>if</B></FONT> __name__ == <FONT COLOR=#115511>'__main__'</FONT>: main()
</PRE>
                  <!--footer-->
                  </BODY>
